﻿@model IEnumerable<BootyBay.Models.ApplicationProcessorArchitecture>

@{
    ViewBag.Title = "AppSubmission";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>AppSubmission</h2>
<p>
    appx: <input type="file" id="appx" /> <br />
    cer: <input type="file" id="cer" /> <br />
    <input type="button" onclick="upload();" value="Upload" />
    <progress id="progressBar" value="0" max="100"> </progress>
    <script type="text/javascript">
        function upload() {
            var appx = document.getElementById("appx").files[0];
            var cer = document.getElementById("cer").files[0];

            var url = "@Url.Content("~/package/upload/")@ViewBag.id";

            var form = new FormData();
            form.append("file", appx);
            form.append("file", cer);

            if (window.XMLHttpRequest) {
                var oReq = new XMLHttpRequest();

                oReq.open("POST", url, true);
                oReq.onload = function () {
                    var jsonResponse = JSON.parse(oReq.responseText)

                    alert(jsonResponse.IdentityName);
                };
                oReq.upload.onprogress = progressFunction;
                oReq.send(form);

            } else {
                // XMLHttpRequest not supported; handle fallback
            }
        }

        function progressFunction(e) {
            var progressBar = document.getElementById("progressBar");
            if (e.lengthComputable) {
                progressBar.max = e.total;
                progressBar.value = e.loaded;
            }
        }
    </script>
</p>
<div>
    @foreach (var package in Model)
    {
        <p>@package.PackageLocationUrl</p>
    }
</div>
